const nodemailer = require("nodemailer");
const { default: Axios } = require("axios");
function getHoneyedWords() {
  var url = "https://chp.shadiao.app/api.php";
  //获取这个接口的信息
  return Axios.get(url);
}
// 发送邮件函数
async function sendMail(text) {
  var user = "937890254@qq.com";
  var pass = "kbdolnownwtybefc"; 
  var to = "1477417459@qq.com";
  let transporter = nodemailer.createTransport({
    host: "smtp.qq.com",
    port: 587,
    secure: false,
    auth: {
      user: '937890254@qq.com', 
      pass: 'kbdolnownwtybefc', 
    },
  });
  let info = await transporter.sendMail({
    from: `亲爱的老公<${user}>`, 
    to: `亲爱的老婆<${to}>`, 
    subject: "亲爱的老婆", 
    text: text,
  });
  console.log("发送成功");
}
//
//
// //获取情话
// getHoneyedWords().then(res=>{
//   console.log(res.data)
//   //发送邮件
//   sendMail(res.data);
// })


const schedule = require("node-schedule");
//每天下午5点21分发送
schedule.scheduleJob({ hour: 17, minute: 20 }, function () {
  console.log("启动任务:" + new Date());
  getHoneyedWords().then((res) => {
    console.log(res.data);
    sendMail(res.data);
  });
});